package com.greendragon.persistence.enmu; 

import org.apache.commons.lang.StringUtils;

/** 
 * @author wulibin, exceptsky@gmail.com, 2011-12-6 下午08:05:47
 * 
 */
public enum UserRoleType {
	USER(1, "user"),
	ADMIN(2, "admin"),
	SUPERADMIN(3, "superadmin");

	private int  index;
	private String  name;
	
    private UserRoleType(int index, String name) {
    	this.index = index;
    	this.name = name;
    }
    
    public static UserRoleType getByName(String role){
    	if(StringUtils.isEmpty(role)){
    		return UserRoleType.USER;
    	}else if(role.equalsIgnoreCase("admin")){
    		return UserRoleType.ADMIN;
    	}else if(role.equalsIgnoreCase("superadmin")){
    		return UserRoleType.SUPERADMIN;
    	}else{
    		return UserRoleType.USER;
    	}
    }

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public String toString() {
		return this.name;
	}
}
 